package com.lh.dao;

import com.lh.entity.Cart;
import com.lh.entity.OrdersCart;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @Author: LuoHang
 * @Date: 2021/2/15 17:12
 * @Description
 */
@Repository
public class CartDao {
    @Autowired
    private SqlSessionTemplate sessionTemplate;

    public List<Cart> getCarts(Integer id){
        return sessionTemplate.selectList("CartMapper.getCarts",id);
    }

    public int addCart(Map<String,Object> map){
        return sessionTemplate.insert("CartMapper.addCart",map);
    }

    public int deleteCartById(Integer id){
        return sessionTemplate.delete("CartMapper.deleteCartById",id);
    }

    public int updateCart(Map<String,Object> map){
        return sessionTemplate.update("CartMapper.updateCart",map);
    }

    public int getCartNums(Map<String,Integer> map){
        return sessionTemplate.selectOne("CartMapper.getCartNums",map);
    }

    public Cart getCartByUserIdGoodsId(Map<String,Object> map){
        return sessionTemplate.selectOne("CartMapper.getCartByUserIdGoodsId",map);
    }

    public int addOrdersCart(OrdersCart ordersCart){
        return sessionTemplate.insert("CartMapper.addOrdersCart",ordersCart);
    }

    public Cart getCartById(Integer id){
        return sessionTemplate.selectOne("CartMapper.getCartById",id);
    }
}
